package com.wch.SpringBootTestDemo.controller;

import javax.jms.Destination;

import org.apache.activemq.command.ActiveMQQueue;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.wch.SpringBootTestDemo.activemq.JMSProducter;

@SuppressWarnings("all")
@Controller
@RequestMapping("/mqController")
public class TestMqController {

	@Autowired
	private JMSProducter jmsProducter;
	
	@RequestMapping("/activeMqSendMessage")
	@ResponseBody
	public String activeMqSendMessage(){
		try {
			Destination destination = new ActiveMQQueue("message_queue");
			for (int i = 0; i <10; i++) {
				jmsProducter.converAndSend(destination, "这是生产者生产的第"+i+"个消息！");
			}
			return "activeMQ生产成功";
		} catch (Exception e) {
			return "activeMQ生产失败";
		}
	}
	
}
